home *** CD-ROM | disk | FTP | other *** search
/ Aminet 51 / Aminet 51 (2002)(GTI - Schatztruhe)[!][Oct 2002].iso / Aminet / dev / c / minigl.lha / MiniGL / src / vertexarray.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-05-25  |  3.8 KB  |  137 lines

  1. #ifndef VERTEXARRAY_H
  2. #define VERTEXARRAY_H 1
  3.  
  4. #include "sysinc.h"
  5.  
  6.  
  7. typedef void (*Convfn)(struct GLcontext_t *, int);
  8.  
  9.  
  10. /*
  11. ** Note that the following defines are poking directly into
  12. ** the W3D_Context. This is ofcourse not future-proof, but
  13. ** it avoids a significant overhead.
  14. ** Especially compiled arrays and glDrawElements relies on
  15. ** fast pointer-switch
  16. */
  17.  
  18. #ifndef __VBCC__ //inlines that bypasses the library call
  19.  
  20. static INLINE void Set_W3D_Texture (W3D_Context *w3dctx, int u, W3D_Texture *tex)
  21. {
  22.     w3dctx->CurrentTex[u] = tex;
  23. }
  24.  
  25. static INLINE void Set_W3D_ColorPointer (W3D_Context *w3dctx, void *pointer, int stride, ULONG format, ULONG mode, ULONG flags)
  26. {
  27.     w3dctx->ColorPointer = pointer;
  28.     w3dctx->CPStride = stride;
  29.     w3dctx->CPMode = mode | format;
  30.     w3dctx->CPFlags = flags;
  31. }
  32.  
  33. static INLINE void Set_W3D_TexCoordPointer (W3D_Context *w3dctx, void *pointer, int stride, int u, int v_off, int w_off, ULONG flags)
  34. {
  35.     w3dctx->TexCoordPointer[u] = pointer;
  36.     w3dctx->TPStride[u] = stride;
  37.     w3dctx->TPVOffs[u] = v_off;
  38.     w3dctx->TPWOffs[u] = w_off;
  39.     w3dctx->TPFlags[u] = flags;
  40. }
  41.  
  42. static INLINE void Set_W3D_VertexPointer (W3D_Context *w3dctx, void *pointer, int stride, ULONG mode, ULONG flags)
  43. {
  44.     w3dctx->VertexPointer = pointer;
  45.     w3dctx->VPStride = stride;
  46.     w3dctx->VPMode = mode;
  47.     w3dctx->VPFlags = flags;
  48. }
  49.  
  50. static INLINE void Reset_W3D_ArrayPointers (GLcontext glctx, GLbitfield cls)
  51. {
  52.     if(cls & GLCS_VERTEX)
  53.     {
  54.     glctx->w3dContext->VertexPointer = (void *)&glctx->VertexBuffer[0].bx;
  55.     glctx->w3dContext->VPStride = (int)sizeof(MGLVertex);
  56.     glctx->w3dContext->VPMode = W3D_VERTEX_F_F_F;
  57.     glctx->w3dContext->VPFlags = 0;
  58.     }
  59.  
  60.     if(cls & GLCS_COLOR)
  61.     {
  62.     glctx->w3dContext->ColorPointer = (void *)glctx->ArrayPointer.colors;
  63.     glctx->w3dContext->CPStride = (int)glctx->ArrayPointer.colorstride;
  64.     glctx->w3dContext->CPMode = (ULONG)glctx->ArrayPointer.colormode;
  65.     }
  66.  
  67.     if(cls & GLCS_TEXTURE)
  68.     {
  69.     glctx->w3dContext->TexCoordPointer[0] = (void *)glctx->ArrayPointer.texcoords;
  70.     glctx->w3dContext->TPStride[0] = (int)glctx->ArrayPointer.texcoordstride;
  71.     glctx->w3dContext->TPWOffs[0] = (int)glctx->ArrayPointer.w_off;
  72.     }
  73. }
  74.  
  75. #else
  76.  
  77. //macros that bypasses the library call:
  78.  
  79. #define Set_W3D_Texture(w3dctx,u,tex) \
  80. { \
  81.     w3dctx->CurrentTex[(int)u] = (W3D_Texture *)tex;    \
  82. }
  83.  
  84. #define Set_W3D_ColorPointer(w3dctx,pointer,stride,format,mode, flags) \
  85. { \
  86.     w3dctx->ColorPointer = (void *)pointer;        \
  87.     w3dctx->CPStride = (int)stride;            \
  88.     w3dctx->CPMode = ((ULONG)mode | (ULONG)format);    \
  89.     w3dctx->CPFlags = (ULONG)flags;            \
  90. }
  91.  
  92. #define Set_W3D_TexCoordPointer(w3dctx,pointer,stride,u,v_off, w_off,flags) \
  93. { \
  94.     w3dctx->TexCoordPointer[(int)u] = (void *)pointer;    \
  95.     w3dctx->TPStride[(int)u] = (int)stride;        \
  96.     w3dctx->TPVOffs[(int)u] = (int)v_off;        \
  97.     w3dctx->TPWOffs[(int)u] = (int)w_off;        \
  98.     w3dctx->TPFlags[(int)u] = (ULONG)flags;        \
  99. }
  100.  
  101. #define Set_W3D_VertexPointer(w3dctx,pointer,stride,mode,flags) \
  102. { \
  103.     w3dctx->VertexPointer = (void *)pointer;    \
  104.     w3dctx->VPStride = (int)stride;            \
  105.     w3dctx->VPMode = (ULONG)mode;            \
  106.     w3dctx->VPFlags = (ULONG)flags;            \
  107. }
  108.  
  109.  
  110. #define Reset_W3D_ArrayPointers(glctx, cls) \
  111. { \
  112. if(cls & GLCS_VERTEX)\
  113. {\
  114. glctx->w3dContext->VertexPointer = (void *)&glctx->VertexBuffer[0].bx;\
  115. glctx->w3dContext->VPStride = (int)sizeof(MGLVertex);\
  116. glctx->w3dContext->VPMode = W3D_VERTEX_F_F_F;\
  117. glctx->w3dContext->VPFlags = 0;\
  118. } \
  119. if(cls & GLCS_COLOR) \
  120. { \
  121. glctx->w3dContext->ColorPointer = (void *)glctx->ArrayPointer.colors; \
  122. glctx->w3dContext->CPStride = (int)glctx->ArrayPointer.colorstride; \
  123. glctx->w3dContext->CPMode = (ULONG)glctx->ArrayPointer.colormode; \
  124. } \
  125. \
  126. if(cls & GLCS_TEXTURE) \
  127. { \
  128. glctx->w3dContext->TexCoordPointer[0] = (void *)glctx->ArrayPointer.texcoords; \
  129. glctx->w3dContext->TPStride[0] = (int)glctx->ArrayPointer.texcoordstride; \
  130. glctx->w3dContext->TPWOffs[0] = (int)glctx->ArrayPointer.w_off; \
  131. } \
  132. }
  133.  
  134. #endif
  135.  
  136. #endif
  137.